// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import { error } from "console";
import ComponentBase from "../BASE/ComponentBase";
import KHD from "../Message/KHD";
import KHD2 from "../Message/KHD2";
import turn from "../game/time/turn";
import YP from "../../sound/music";

const {ccclass, property} = cc._decorator;

@ccclass
export default class endGame extends ComponentBase {
static game:number=-1
static blue:number=0;
static red:number=0;
static jsl:boolean=false
 qd(){
    
    const data = {
        id:7,
        error:0
       
       };
     
     
     
     
     KHD2.socket.send(JSON.stringify(data))
     
    }

 static start(): void {
    KHD2.Gammer.on("gameEnd",(data)=>{


switch (KHD2.ingame) {
    case 0:endGame.window()
        
        break;

    default:if(KHD2.ingame==data[0]){endGame.window()}
        break;


    }


//KHD2.ST()
    })
}

static window(){
let node=cc.find("")
node.active=true
for (let index = 0; index <endGame.blue; index++) {
   node.children[0].children[3].active=true
    
}
for (let index = 0; index <endGame.blue; index++) {
    node.children[1].children[3].active=true
    
}
}


static endGame(p:number){
switch (p) {
    case 0:endGame.blue+=1;
        
        break;
case 9:
    break;
    default:endGame.red+=1;
        break;
}

/*
if ((endGame.blue==3||endGame.red==3)&&turn.turn==KHD.PT) {
    KHD.Gammer.emit("gameEnd",[endGame.blue,endGame.red])
}*/

if ((endGame.blue==3||endGame.red==3)){

      
        let node=cc.find("Canvas/UIManager/endgame")
node.active=true
endGame.JS()
}

let node=cc.find("Canvas/UIManager/SJ")

for (let index = 0; index < endGame.blue; index++) {
    node.children[2].children[index].active=true
    
}
for (let index = 0; index < endGame.red; index++) {
    node.children[1].children[index].active=true
    
}


}

static JS(){

for (let index = 0; index < endGame.blue; index++) {
    cc.find("Canvas/UIManager/endgame/blue").children[index].active=true
    
}

for (let index = 0; index < endGame.red; index++) {
    cc.find("Canvas/UIManager/endgame/red").children[index].active=true
    
}

switch (KHD2.PT[0]%2) {
    case 0:if(endGame.red==3){
        cc.find("Canvas/UIManager/endgame/win").active=true
   endGame.jsl=true

   cc.find("Canvas").getComponent(YP).PlayAudioclip("qyp",false,0)
    }else{cc.find("Canvas/UIManager/endgame/lose").active=true

        cc.find("Canvas").getComponent(YP).PlayAudioclip("qyp",false,1)

    }
        
        break;

    default:if(endGame.blue==3){
        cc.find("Canvas/UIManager/endgame/win").active=true
        endGame.jsl=true
    }else{cc.find("Canvas/UIManager/endgame/lose").active=true}
        break;
}
 



}






}
